package com.suray.wcs.res.enums;

import com.alibaba.fastjson.serializer.JSONSerializable;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.fasterxml.jackson.annotation.JsonValue;

import java.io.IOException;
import java.lang.reflect.Type;

public enum RgvGroupStatus  implements JSONSerializable {
    /**
     * 就绪（1）
     */
    READY(1, "就绪"),
    /**
     * 运行（2）
     */
    WORKING(2, "运行"),
    /**
     * 故障(3)
     */
    ERROR(3, "故障"),
    /**
     * 充电中
     */
    CHARGING(4, "充电"),
    /**
     * 下线(5)
     */
    PAUSE_LINE(5, "下线"),
    /**
     * 离线（6）
     */
    OFF_LINE(6, "离线"),
    /**
     * 未知状态
     */
    UNKNOWN(-1, "未知"),
    ;
    private int rgvGroupStatus;
    private String description;

    RgvGroupStatus(int rgvGroupStatus, String description) {
        this.rgvGroupStatus = rgvGroupStatus;
        this.description = description;
    }

    public static RgvGroupStatus parseStatus(int status) {
        RgvGroupStatus[] rgvGroupStatuses = RgvGroupStatus.values();
        for (RgvGroupStatus rgvGroupStatus : rgvGroupStatuses) {
            if (rgvGroupStatus.rgvGroupStatus == status) {
                return rgvGroupStatus;
            }
        }
        return UNKNOWN;
    }

    public static RgvGroupStatus parseByRgvStatus(RgvStatus rgvStatus){
        switch (rgvStatus){
            case READY:
                return READY;
            case RUNING:
            case MOVING:
            case NODE_STANDBY:
            case PAUSE:
            case SEND_MAP:
            case EXTRACT_LOG:
                return WORKING;
            case ERROR:
                return ERROR;
            case CHARGING:
                return CHARGING;
            default:
                return OFF_LINE;
        }
    }

    public int getRgvGroupStatus() {
        return rgvGroupStatus;
    }

    @JsonValue
    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return description;
    }

    @Override
    public void write(JSONSerializer jsonSerializer, Object arg1, Type arg2, int arg3) throws IOException {
        jsonSerializer.write(this.getDescription());
    }
}
